<layout name="page" />
<block name="content">
	<select name="weixin_menu_list" id="weixin_menu_list" class="hidden">
		<option value="0">无</option>
		{:fill_option($weixin_menu_list)}
	</select>
	{:widget('page_header/simple',array('name'=>'系统参数'))}
	<div class="tab-header">
		<a href="{:url('index')}">基本设置</a>
		<a href="{:url('weixin')}">微信设置</a>
		<a class="active">微信菜单</a>
		<a href="{:url('config')}">系统参数</a>
		<a href="{:url('push')}">推送设置</a>
	</div>
	<div class="operate-panel">
		<label class="label w9">微信应用:</label>
		<form id="form_search" name="form_search" method="post">
			<div class="input-box" style="display:flex;margin-right: 4px;">
				<select class="select w12" id="eq_pid" name="eq_pid" >
					{:fill_option($top_node)}
				</select>
				<i class="icon"></i>
			</div>
		</form>
		<i class="mid"></i>
		<a class="btn btn-normal" onclick="release()">发布</a>
		<a class="btn btn-normal" onclick="add_weixin_menu()">新增菜单</a>
		<a class="btn btn-normal" onclick="save()">保存</a>
		<i class="split"></i>
		<a class="btn btn-del" onclick="del()">删除</a>
	</div>
	<div class="x1 sub box">
		<div class="w30 m100 frame" style="max-height: 500px;">
			<div class="tree-menu">
				<a node="{$eq_pid}" style="padding-left:8px;width:100%;display:block;line-height: 32px;">{$pid_name}</a>
				<php>
					if(!empty($tree_menu)){
				</php>
				<input type="hidden">
				<php>
					}
				</php>
			</div>
			<div class="tree-menu">
				{:widget('html/tree_menu',array($tree_menu))}
			</div>
		</div>
		<div style="width:16px;"></div>
		<div class="x1 frame" style="height:500px;">
			<form id="form_data" name="form_data" method="post" class="weixin">
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="opmode" id="opmode">
				<div class="box">
					<label class="input-label" for="name">菜单名称*：</label>
					<input class="input w19" type="text" id="name" name="name" check="required" info="请输入菜单名称">
				</div>
				<div class="box" style="margin-bottom:0px;">
					<label class="input-label" for="val">事件选择*：</label>
					<select class="select" name="type" id="type">
						<option value="click">点击推事件</option>
						<option value="view">跳转URL</option>
						<option value="scancode_push">扫码推事件</option>
						<option value="scancode_waitmsg">扫码推事件且弹出“消息接收中”提示框</option>
						<option value="pic_sysphoto">弹出系统拍照发图</option>
						<option value="pic_photo_or_album">弹出拍照或者相册发图</option>
						<option value="location_select">弹出地理位置选择器</option>
						<option value="media_id">下发消息（除文本消息）</option>
						<option value="view_limited">跳转图文消息URL</option>
					</select>
					<i class="icon"></i>
				</div>
				<div class="box" style="font-size:14px;height:21px;">
					<label class="input-label"></label>注：需要进行链接的事件为view事件
				</div>
				<div class="box" style="margin-bottom:0px;">
					<label class="input-label" for="url">URL*：</label>
					<input class="input" type="text" id="url" name="url"  >
				</div>
				<div class="box" style="font-size:14px;height:21px;">
					<label class="input-label"></label>注：示例链接形式：index.php?m=&c=Task&a=folder&fid=all
				</div>
				<div class="box" style="margin-bottom:0px;">
					<label class="input-label" for="key">Key*：</label>
					<input class="input" type="text" id="key" name="key" >
				</div>
				<div class="box" style="font-size:14px;height:21px;">
					<label class="input-label"></label>注：每个菜单需要有单独的key
				</div>
				<div class="box">
					<label class="input-label" for="pid_name">父级*：</label>
					<div class="input-box w19">
						<input name="pid" id="pid" type="hidden" info="请选择父级" check="required" />
						<input name="pid_name" class="input" id="pid_name" type="text" readonly="readonly" info="请选择父级" check="required"/>
						<a class="add-on w6" onclick="select_weixin_menu()" > 选择 </a>
					</div>
				</div>
				<div class="box">
					<label class="input-label" for="sort">排序：</label>
					<input class="input w10" type="text" id="sort" name="sort" >
				</div>
				<p class="text-right" style="font-size:14px;">
					*一级菜单最多三个，二级菜单最多五个
				</p>
			</form>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use('global', function() {
			set_val('eq_pid', '{$eq_pid}');
			var fn = {
				release : function() {
					winopen("{:url('release')}", 560, 470);
				},
				add_weixin_menu : function() {
					winopen("{:url('add_weixin_menu')}", 560, 470);
				},
				save : function() {
					send_form("form_data", "{:url('save_weixin_menu')}", "{:url('weixin_menu')}", function(ret) {
						if (ret.status) {
							layer.msg(ret.info, {
								time : 1200
							}, function() {
								location.reload(true);
							});
						} else {
							layer.msg(ret.info);
							return false;
						}
					});
				},
				del : function() {
					if ($(".tree-menu a.active").length == 0) {
						layer.msg('请选择要删除的菜单');
						return false;
					}
					if ($(".tree-menu a.active + input").length > 0) {
						layer.msg('有子菜单不能删除');
						return false;
					}
					//信息框-例2
					layer.msg('确定要删除吗?', {
						time : 0,
						btn : ['确定', '取消'],
						yes : function(index) {
							var vars = $("#form_data").serialize();
							send_ajax("{:url('del_weixin_menu')}", vars, function(ret) {
								if (ret.status) {
									layer.msg(ret.info, {
										time : 1200
									}, function() {
										location.reload(true);
									});
								}
							});
						},
						no : function(index) {
							layer.close(index);
						}
					});
				},
				select_weixin_menu : function() {
					winopen("{:url('select_weixin_menu')}", 560, 470);
				},
			};
			win_exp(fn);

			$(".tree-menu a").click(function() {
				$(".tree-menu a.active").removeClass("active");
				$this = $(this);
				$this.addClass("active");
				var vars = {};
				vars.id = $this.attr('node');
				send_ajax("{:url('edit')}", vars, function(ret) {
					show_data(ret);
				});
				return false;
			});

			function show_data(result) {
				for (var s in result.data) {
					set_val(s, result.data[s]);
				}
				$("#pid_name").val($("#weixin_menu_list option[value='" + $("#pid").val() + "']").text());
				$("#opmode").val("edit");
			};
			$('#eq_pid').on('change', function() {
				$('#form_search').submit();
			});
		});

	</script>
</block>